package observer.a;

public class ForecastDisplay implements Observer, DisplayElement {

	private Subject subject;
	
	private WeatherDataObject data;
	
	public ForecastDisplay(Subject subject) {
		this.subject = subject;
		subject.registerObserver(this);
	}

	public void update(Subject subject,Object data) {
		
		if (data instanceof WeatherDataObject) {
			WeatherDataObject wdata = (WeatherDataObject)data;
			this.data = wdata;
		}
		
		display();
	}

	public void display() {
		
		String forecast = "";
		
		if (data.getTemperature() < 0) {
			forecast = "cold";
		} else if (data.getTemperature() < 10) {
			forecast = "cool";
		} else if (data.getTemperature() < 20) {
			forecast = "warm";
		} else {
			forecast = "hot";
		}
		
		System.out.println("Forecast wether:---> "+forecast+"!");
	}

}
